<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>结清对客IRR计算</title>
    <jsp:include page="../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" value="" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">结清金额</div>
                    <div class="field">
                        <input name="amount" id="amount" type="text" value="" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">结清时间</div>
                    <div class="field">
                        <input ligerui="width: 100" name="trialDate" id="trialDate" value="" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="formBtns notRight">
                    <span id="trialBtn" class="sq-button sq-button-round"></i>计算</span>
                    <%--<span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>--%>
                </div>
            </div>
        </form>
    </div>

    <div id="pageInTab" class="pageInTab">
        <form id="settleDataForm">
            <div class="fieldset1 tabel_col clearFix">
                <div class="fieldBox col_100">
                    <div class="label">合规IRR</div>
                    <div class="field">
                        <span id="irrConfig"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">实际IRR</div>
                    <div class="field">
                        <span id="actIrr"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">最终IRR</div>
                    <div class="field">
                        <span id="irr"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">历史还款NPV</div>
                    <div class="field">
                        <span id="historyRepayNPV"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">实际应还总额</div>
                    <div class="field">
                        <span id="actRepay"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">结清优惠金额1</div>
                    <div class="field">
                        <span id="discountAmtIRR"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label"><b>最终应付结清金额</b></div>
                    <div class="field">
                        <span id="finalStlAmt"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">入金明细</div>
                    <div class="field">
                        <span id="inCash"></span>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">出金明细</div>
                    <div class="field">
                        <span id="outCash"></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    var basePath = '<%=path%>';
    $(function () {


        $("#searchBar").ligerForm();

        /* 计算 */
        $("#trialBtn").click(function (event) {
            var stlAmt = $("#amount").val();
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {paySchNo: $("#paySchNo").val(), amount: stlAmt, trialDate: $("#trialDate").val()},
                url: basePath + "/settlement/trialIRR.do",
                /*beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },*/
                success: function (msg) {
                    //wait_dialog.close();
                    if (msg.success == 1) {
                        $("#actIrr").html(toPercent(msg.data.actIrr));
                        $("#irrConfig").html(toPercent(msg.data.irrConfig));
                        $("#irr").html(toPercent(msg.data.irr));

                        $("#historyRepayNPV").html(formatAmt(msg.data.historyRepayNPV));
                        $("#actRepay").html(formatAmt(msg.data.actRepay*-1));
                        $("#discountAmtIRR").html(formatAmt(msg.data.discountAmtIRR));
                        $("#finalStlAmt").html(formatAmt(NumberUtils.sub(stlAmt*100, msg.data.discountAmtIRR)));

                        var inCash = msg.data.inCash;
                        var outCash = msg.data.outCash;
                        var inCashHtml = "", outCashHtml = "";
                        for (var key in inCash) {
                            inCashHtml += "日期：" + key + ",  金额：" + formatAmt(inCash[key]) + "</br>";
                        }
                        for (var key in outCash) {
                            outCashHtml += "日期：" + key + ",  金额：" + formatAmt(outCash[key]) + "</br>";
                        }

                        $("#inCash").html(inCashHtml);
                        $("#outCash").html(outCashHtml);
                    } else {
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        });

    });

    function toPercent(point) {
        if (point == 0) {
            return 0;
        }
        var str = Number(point * 100).toFixed(2);
        str += "%";
        return str;
    }

    function formatAmt(value) {
        if (StringUtils.isEmpty(value)) {
            return '———';
        } else {
            if (value > 0) {
                return '<font color="green">&yen;' + FormatMoney(value / 100) + '</font>';
            } else if (value == 0) {
                return '&yen;' + FormatMoney(value / 100);
            } else {
                return '<font color="red">-&yen;' + FormatMoney(Math.abs(value) / 100) + '</font>';
            }
        }
    }

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

</script>

</body>
</html>
